package cc.bable.nexus.api;

import act.app.ActionContext;
import act.controller.Controller;
import org.osgl.aaa.NoAuthentication;
import org.osgl.mvc.annotation.Action;
import org.osgl.mvc.annotation.PostAction;
import org.osgl.mvc.annotation.ResponseStatus;

/**
 * @author Genko Lee
 */
@NoAuthentication
@Controller("/api")
public class LoginEndpoint extends Controller.Util {

    @PostAction("login")
    @ResponseStatus(200)
    public void login(String username, String password, ActionContext context) {
        if (username.equals("admin") && password.equals("111111")) {
            context.login("admin");
        } else {
            unauthorizedIf(true);
        }
    }

    @Action("logout")
    @ResponseStatus(200)
    public void logout(ActionContext context) {
        context.logout();
    }

}
